package cn.iocoder.yudao.module.product.category.api;

import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.api.product.category.ProductCategoryApi;
import cn.iocoder.yudao.module.api.product.category.dto.CategoryRespDTO;
import cn.iocoder.yudao.module.product.category.dal.dataobject.ProductCategoryDO;
import cn.iocoder.yudao.module.product.category.service.ProductCategoryService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import java.util.List;
import java.util.Set;

/**
 * 产品分类 API 接口实现类
 *
 * @author owen
 */
@Service
@Validated
public class ProductCategoryApiImpl implements ProductCategoryApi {

    @Resource
    private ProductCategoryService productCategoryService;

    @Override
    public void validateCategoryList(Set<Long> ids) {
        productCategoryService.validateCategoryList(ids);
    }

    @Override
    public List<CategoryRespDTO> getCategoryList(Set<Long> ids) {
        List<ProductCategoryDO> list = productCategoryService.getEnableCategoryList(ids);
        return BeanUtils.toBean(list, CategoryRespDTO.class);
    }

    @Override
    public List<CategoryRespDTO> getCategoryListByParentId(Long parentId) {
        List<ProductCategoryDO> list = productCategoryService.getEnableCategoryList(CollUtil.newHashSet(parentId));
        return BeanUtils.toBean(list, CategoryRespDTO.class);
    }

}
